/* controller example for google map component */

public class GoogleMapController {
	
    // or whatever you need to return a valid key to the component
    //public string forcekey { get { return geoApiKey.key; }}
    public static string forcekey { get { return 'ABQIAAAAwH_cWdbXSC9yVBGIoIdx-BQRmoUgOUS0AdglA8vMXXHrIXZp6RTDmBzNZ6Md34q0zLNhY9w-hPjhsg';}}
    
    Account[] accounts = new Account[]{};
    
    Account[] init() { 
     	if (accounts.size() > 0 ) return accounts;
    	accounts = [select name, description, 
            Latitue__c, Longitute__c ,
            website, phone, billingcity, billingstate
                from account
                where geocode_status__c = 'G_GEO_SUCCESS'
                limit 14];
        return accounts;
    }
    
    public string geoDataTable { get { 
    	init();
        GoogleViz gv = new GoogleViz();
        gv.cols = new list<GoogleViz.col> { 
            new GoogleViz.Col('A','Lat','n'),
            new GoogleViz.Col('B','Lon','n'),
            new GoogleViz.Col('C','Name','t') 
        };
        for (Account a: accounts ) {
        	googleViz.row rr = new googleViz.row();
        	rr.cells.add ( new GoogleViz.cell( a.Latitue__c ) ); 
            rr.cells.add ( new GoogleViz.cell( a.Longitute__c ) ); 
            string descript =  a.name +  a.billingCity + ', ' +
            a.billingstate +a.phone ;
            if ( a.website != null ) { descript += a.website ; }
        	rr.cells.add ( new GoogleViz.cell( descript ) ); 
        	gv.addRow( rr ); 
        }
        
        return gv.toJsonString(); 
    } }     
    
	public static testmethod void t1() {
		GoogleMapController c = new GoogleMapController();
		c.init(); 
		system.assert( c.geoDataTable != null );
	}	
}